// Surroundings/status/status.js
var util = require("../../utils/util.js");
var api = require("../../config/api.js");
Page({

    /**
     * 页面的初始数据
     */
    data: {
        info: {
            1: {
                icon: "icon-yingyezhong",
                status: "营业中",
                info: "幸福生活靠自己～",
                btnText: "开始休息"
            },
            0: {
                icon: "icon-xiudianzhong",
                status: "休店中",
                info: "快快开店营业吧～",
                btnText: "开始营业"
            },
            3: {
                icon: "icon-zhifuchenggong",
                status: "店铺已认证",
                info: "",
                btnText: "解除认证并退回押金"
            }
        },
        currentInfo: {},
        merchatInfo: {}
            
    },

    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function (options) {
        options.status = options.status || 1;
        this.setData({
            status: options.status,
            currentInfo: this.data.info[options.status]
        })
        if(options.status == 3){
            this.getData();
        }
    },

    /**
     * 生命周期函数--监听页面初次渲染完成
     */
    onReady: function () {

    },

    /**
     * 生命周期函数--监听页面显示
     */
    onShow: function () {

    },

    /**
     * 生命周期函数--监听页面隐藏
     */
    onHide: function () {

    },

    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function () {

    },

    /**
     * 页面相关事件处理函数--监听用户下拉动作
     */
    onPullDownRefresh: function () {

    },

    /**
     * 页面上拉触底事件的处理函数
     */
    onReachBottom: function () {

    },

    openOrCloseMerchant(){
        wx.showLoading({
            title: "正在申请",
        })
        const userInfo = wx.getStorageSync("userInfo");
        const status = this.data.status == 1 ? false : true;
        if(this.data.status == 3){
            util.request(api.surroundings.applyRefundDeposit + this.data.merchatInfo.id, {}, "POST").then(res=>{
                wx.showToast({
                    title: res.message,
                    icon: "none"
                })
                wx.hideLoading();
                wx.navigateBack();
            }).catch(err=>{
                console.log("err", err);
                wx.hideLoading();
                wx.showToast({
                    title: err.message,
                    icon: "none"
                })
            })
            return ;
        }
        util.request(api.surroundings.openOrCloseMerchant, {
            id: userInfo.merchantId,
            status: status
        }, "POST").then(res=>{
            wx.showToast({
                title: res.message,
                icon: "none"
            })
            wx.hideLoading();
            wx.navigateBack();
        }).catch(err=>{
            console.log("err", err);
            wx.hideLoading();
            wx.showToast({
                title: err.message,
                icon: "none"
            })
        })
    },
    getData(){
        wx.showLoading({
            title: "正在加载",
        })
        util.request(api.surroundings.getStoreRealName, {}, "POST").then(res=>{
            console.log(res.result, "12");
            const data = res.result;
            this.setData({
                back: data.backCard,
                licence: data.businessLicense,
                personSign: data.personSign,
                positive: data.positiveCard,
                merchatInfo: data,
            })
            wx.hideLoading();
        })
    }
})